//
//  HomeHeaderView.swift
//  EyeVisionForPatients
//
//  Created by PMC on 2020/3/9.
//  Copyright © 2020 tao Tao. All rights reserved.
//

import UIKit

class HomeHeaderView: UIView {
    
    var viewTapped: ((_ type: HomeButtonViewType) -> Void)?

    private lazy var bannerView = BannerView()
    
//    lazy var centerView = UINib.loadViewFrom(HomeCenterView.self)
    

    private lazy var bottomView = UINib.loadViewFrom(HomeBottomView.self)
        
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    convenience init(with vc: UIViewController?, imageArr: [String] = []) {
        self.init()
        backgroundColor = .clear
        bannerView.delegate = vc as? BannerViewDelegate
        bannerView.imageUrls = imageArr
        bannerView.isAutoScroll = true
        addSubview(bannerView)
        addSubview(bottomView)
        
        bottomView.viewTapped = { [weak self] type in
            self?.viewTapped?(type)
        }

        bottomView.configureUI()
    }
    
    override func layoutSubviews() {
        super.layoutSubviews()
        bannerView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(16)
            make.right.equalToSuperview().offset(-16)
            make.top.equalToSuperview().offset(4)
            make.height.equalTo(132)
        }
        
        bottomView.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.top.equalTo(bannerView.snp.bottom).offset(20)
            make.bottom.equalToSuperview().offset(-10)
        }

    }
    
    func reloadData(with vm: YSGHomeViewModel, isTop: Bool = true) {
        if isTop {
            bannerView.viewModel = vm.topBannerVm()
        } else {
            bannerView.viewModel = vm.centerBannerVm()
        }
    }
}
